package com.woniu.controller;

import com.woniu.entity.Atten;
import com.woniu.entity.response.ResponseEntity;
import com.woniu.entity.vo.AttenVo;
import com.woniu.entity.vo.PageResponseVo;
import com.woniu.service.IAttenService;
import com.woniu.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
@RestController
@RequestMapping("/brain/atten")
public class AttenController {
    @Autowired
    public IAttenService attenService;

    @PostMapping("/signin")
    public ResponseEntity signIn(@RequestBody AttenVo attenVo) throws ParseException {
        return ResponseEntity.success("", attenService.signIn(attenVo));
    }

    @PostMapping("/page")
    public ResponseEntity selectAttentPage(@RequestParam(required = false, defaultValue = "0") Integer page,
                                           @RequestParam(required = false, defaultValue = "10") Integer count) {
        PageResponseVo<Atten> attendance = attenService.getAttenPage(page, count);
        return ResponseEntity.success(attendance);
    }

    @PostMapping("/pagebyterms")
    public ResponseEntity selectAttenByTerms(@RequestParam(required = false, defaultValue = "0") Integer page,
                                             @RequestParam(required = false, defaultValue = "10") Integer count,
                                             @RequestBody Atten atten) {
        PageResponseVo<Atten> attendance = attenService.getAttenPageByTerms(page, count, atten);
        return ResponseEntity.success(attendance);
    }

    @PostMapping("/update/absenteeism")
    public ResponseEntity updateAttendance(@RequestParam String date) {
        Integer countNotAttenAllDay = attenService.updateNotAttenAllDay(date);
        Integer countNotAttenOffWork = attenService.updateNotAttenOffWork(date);
        return ResponseEntity.success("", "已处理记录" + (countNotAttenAllDay + countNotAttenOffWork) + "条");
    }

    @PostMapping("/updateone")
    public ResponseEntity updateOne(@RequestBody Atten atten) {
        attenService.update(atten);
        return ResponseEntity.success("");
    }

}
